{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generalized Linear Models (Formula)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook illustrates how you can use R-style formulas to fit Generalized Linear Models.\n",
    "\n",
    "To begin, we load the ``Star98`` dataset and we construct a formula and pre-process the data:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import statsmodels.api as sm\n",
    "import statsmodels.formula.api as smf\n",
    "star98 = sm.datasets.star98.load_pandas().data\n",
    "formula = 'SUCCESS ~ LOWINC + PERASIAN + PERBLACK + PERHISP + PCTCHRT + \\\n",
    "           PCTYRRND + PERMINTE*AVYRSEXP*AVSALK + PERSPENK*PTRATIO*PCTAF'\n",
    "dta = star98[['NABOVE', 'NBELOW', 'LOWINC', 'PERASIAN', 'PERBLACK', 'PERHISP',\n",
    "              'PCTCHRT', 'PCTYRRND', 'PERMINTE', 'AVYRSEXP', 'AVSALK',\n",
    "              'PERSPENK', 'PTRATIO', 'PCTAF']].copy()\n",
    "endog = dta['NABOVE'] / (dta['NABOVE'] + dta.pop('NBELOW'))\n",
    "del dta['NABOVE']\n",
    "dta['SUCCESS'] = endog"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then, we fit the GLM model:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>Generalized Linear Model Regression Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>        <td>SUCCESS</td>     <th>  No. Observations:  </th>  <td>   303</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>                  <td>GLM</td>       <th>  Df Residuals:      </th>  <td>   282</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model Family:</th>        <td>Binomial</td>     <th>  Df Model:          </th>  <td>    20</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Link Function:</th>         <td>logit</td>      <th>  Scale:             </th> <td>  1.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Method:</th>                <td>IRLS</td>       <th>  Log-Likelihood:    </th> <td> -127.33</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>            <td>Tue, 24 Dec 2019</td> <th>  Deviance:          </th> <td>  8.5477</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                <td>14:55:59</td>     <th>  Pearson chi2:      </th>  <td>  8.48</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>No. Iterations:</th>          <td>4</td>        <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>     <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "              <td></td>                <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th>                <td>    0.4037</td> <td>   25.036</td> <td>    0.016</td> <td> 0.987</td> <td>  -48.665</td> <td>   49.472</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>LOWINC</th>                   <td>   -0.0204</td> <td>    0.010</td> <td>   -1.982</td> <td> 0.048</td> <td>   -0.041</td> <td>   -0.000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERASIAN</th>                 <td>    0.0159</td> <td>    0.017</td> <td>    0.910</td> <td> 0.363</td> <td>   -0.018</td> <td>    0.050</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERBLACK</th>                 <td>   -0.0198</td> <td>    0.020</td> <td>   -1.004</td> <td> 0.316</td> <td>   -0.058</td> <td>    0.019</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERHISP</th>                  <td>   -0.0096</td> <td>    0.010</td> <td>   -0.951</td> <td> 0.341</td> <td>   -0.029</td> <td>    0.010</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PCTCHRT</th>                  <td>   -0.0022</td> <td>    0.022</td> <td>   -0.103</td> <td> 0.918</td> <td>   -0.045</td> <td>    0.040</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PCTYRRND</th>                 <td>   -0.0022</td> <td>    0.006</td> <td>   -0.348</td> <td> 0.728</td> <td>   -0.014</td> <td>    0.010</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERMINTE</th>                 <td>    0.1068</td> <td>    0.787</td> <td>    0.136</td> <td> 0.892</td> <td>   -1.436</td> <td>    1.650</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AVYRSEXP</th>                 <td>   -0.0411</td> <td>    1.176</td> <td>   -0.035</td> <td> 0.972</td> <td>   -2.346</td> <td>    2.264</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERMINTE:AVYRSEXP</th>        <td>   -0.0031</td> <td>    0.054</td> <td>   -0.057</td> <td> 0.954</td> <td>   -0.108</td> <td>    0.102</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AVSALK</th>                   <td>    0.0131</td> <td>    0.295</td> <td>    0.044</td> <td> 0.965</td> <td>   -0.566</td> <td>    0.592</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERMINTE:AVSALK</th>          <td>   -0.0019</td> <td>    0.013</td> <td>   -0.145</td> <td> 0.885</td> <td>   -0.028</td> <td>    0.024</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AVYRSEXP:AVSALK</th>          <td>    0.0008</td> <td>    0.020</td> <td>    0.038</td> <td> 0.970</td> <td>   -0.039</td> <td>    0.041</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERMINTE:AVYRSEXP:AVSALK</th> <td> 5.978e-05</td> <td>    0.001</td> <td>    0.068</td> <td> 0.946</td> <td>   -0.002</td> <td>    0.002</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERSPENK</th>                 <td>   -0.3097</td> <td>    4.233</td> <td>   -0.073</td> <td> 0.942</td> <td>   -8.606</td> <td>    7.987</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PTRATIO</th>                  <td>    0.0096</td> <td>    0.919</td> <td>    0.010</td> <td> 0.992</td> <td>   -1.792</td> <td>    1.811</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERSPENK:PTRATIO</th>         <td>    0.0066</td> <td>    0.206</td> <td>    0.032</td> <td> 0.974</td> <td>   -0.397</td> <td>    0.410</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PCTAF</th>                    <td>   -0.0143</td> <td>    0.474</td> <td>   -0.030</td> <td> 0.976</td> <td>   -0.944</td> <td>    0.916</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERSPENK:PCTAF</th>           <td>    0.0105</td> <td>    0.098</td> <td>    0.107</td> <td> 0.915</td> <td>   -0.182</td> <td>    0.203</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PTRATIO:PCTAF</th>            <td>   -0.0001</td> <td>    0.022</td> <td>   -0.005</td> <td> 0.996</td> <td>   -0.044</td> <td>    0.044</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERSPENK:PTRATIO:PCTAF</th>   <td>   -0.0002</td> <td>    0.005</td> <td>   -0.051</td> <td> 0.959</td> <td>   -0.010</td> <td>    0.009</td>\n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                 Generalized Linear Model Regression Results                  \n",
       "==============================================================================\n",
       "Dep. Variable:                SUCCESS   No. Observations:                  303\n",
       "Model:                            GLM   Df Residuals:                      282\n",
       "Model Family:                Binomial   Df Model:                           20\n",
       "Link Function:                  logit   Scale:                          1.0000\n",
       "Method:                          IRLS   Log-Likelihood:                -127.33\n",
       "Date:                Tue, 24 Dec 2019   Deviance:                       8.5477\n",
       "Time:                        14:55:59   Pearson chi2:                     8.48\n",
       "No. Iterations:                     4                                         \n",
       "Covariance Type:            nonrobust                                         \n",
       "============================================================================================\n",
       "                               coef    std err          z      P>|z|      [0.025      0.975]\n",
       "--------------------------------------------------------------------------------------------\n",
       "Intercept                    0.4037     25.036      0.016      0.987     -48.665      49.472\n",
       "LOWINC                      -0.0204      0.010     -1.982      0.048      -0.041      -0.000\n",
       "PERASIAN                     0.0159      0.017      0.910      0.363      -0.018       0.050\n",
       "PERBLACK                    -0.0198      0.020     -1.004      0.316      -0.058       0.019\n",
       "PERHISP                     -0.0096      0.010     -0.951      0.341      -0.029       0.010\n",
       "PCTCHRT                     -0.0022      0.022     -0.103      0.918      -0.045       0.040\n",
       "PCTYRRND                    -0.0022      0.006     -0.348      0.728      -0.014       0.010\n",
       "PERMINTE                     0.1068      0.787      0.136      0.892      -1.436       1.650\n",
       "AVYRSEXP                    -0.0411      1.176     -0.035      0.972      -2.346       2.264\n",
       "PERMINTE:AVYRSEXP           -0.0031      0.054     -0.057      0.954      -0.108       0.102\n",
       "AVSALK                       0.0131      0.295      0.044      0.965      -0.566       0.592\n",
       "PERMINTE:AVSALK             -0.0019      0.013     -0.145      0.885      -0.028       0.024\n",
       "AVYRSEXP:AVSALK              0.0008      0.020      0.038      0.970      -0.039       0.041\n",
       "PERMINTE:AVYRSEXP:AVSALK  5.978e-05      0.001      0.068      0.946      -0.002       0.002\n",
       "PERSPENK                    -0.3097      4.233     -0.073      0.942      -8.606       7.987\n",
       "PTRATIO                      0.0096      0.919      0.010      0.992      -1.792       1.811\n",
       "PERSPENK:PTRATIO             0.0066      0.206      0.032      0.974      -0.397       0.410\n",
       "PCTAF                       -0.0143      0.474     -0.030      0.976      -0.944       0.916\n",
       "PERSPENK:PCTAF               0.0105      0.098      0.107      0.915      -0.182       0.203\n",
       "PTRATIO:PCTAF               -0.0001      0.022     -0.005      0.996      -0.044       0.044\n",
       "PERSPENK:PTRATIO:PCTAF      -0.0002      0.005     -0.051      0.959      -0.010       0.009\n",
       "============================================================================================\n",
       "\"\"\""
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mod1 = smf.glm(formula=formula, data=dta, family=sm.families.Binomial()).fit()\n",
    "mod1.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, we define a function to operate customized data transformation using the formula framework:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table class=\"simpletable\">\n",
       "<caption>Generalized Linear Model Regression Results</caption>\n",
       "<tr>\n",
       "  <th>Dep. Variable:</th>        <td>SUCCESS</td>     <th>  No. Observations:  </th>  <td>   303</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model:</th>                  <td>GLM</td>       <th>  Df Residuals:      </th>  <td>   282</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Model Family:</th>        <td>Binomial</td>     <th>  Df Model:          </th>  <td>    20</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Link Function:</th>         <td>logit</td>      <th>  Scale:             </th> <td>  1.0000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Method:</th>                <td>IRLS</td>       <th>  Log-Likelihood:    </th> <td> -127.33</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Date:</th>            <td>Tue, 24 Dec 2019</td> <th>  Deviance:          </th> <td>  8.5477</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Time:</th>                <td>14:57:00</td>     <th>  Pearson chi2:      </th>  <td>  8.48</td> \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>No. Iterations:</th>          <td>4</td>        <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Covariance Type:</th>     <td>nonrobust</td>    <th>                     </th>     <td> </td>   \n",
       "</tr>\n",
       "</table>\n",
       "<table class=\"simpletable\">\n",
       "<tr>\n",
       "              <td></td>                <th>coef</th>     <th>std err</th>      <th>z</th>      <th>P>|z|</th>  <th>[0.025</th>    <th>0.975]</th>  \n",
       "</tr>\n",
       "<tr>\n",
       "  <th>Intercept</th>                <td>    0.4037</td> <td>   25.036</td> <td>    0.016</td> <td> 0.987</td> <td>  -48.665</td> <td>   49.472</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>double_it(LOWINC)</th>        <td>   -0.0102</td> <td>    0.005</td> <td>   -1.982</td> <td> 0.048</td> <td>   -0.020</td> <td>   -0.000</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERASIAN</th>                 <td>    0.0159</td> <td>    0.017</td> <td>    0.910</td> <td> 0.363</td> <td>   -0.018</td> <td>    0.050</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERBLACK</th>                 <td>   -0.0198</td> <td>    0.020</td> <td>   -1.004</td> <td> 0.316</td> <td>   -0.058</td> <td>    0.019</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERHISP</th>                  <td>   -0.0096</td> <td>    0.010</td> <td>   -0.951</td> <td> 0.341</td> <td>   -0.029</td> <td>    0.010</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PCTCHRT</th>                  <td>   -0.0022</td> <td>    0.022</td> <td>   -0.103</td> <td> 0.918</td> <td>   -0.045</td> <td>    0.040</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PCTYRRND</th>                 <td>   -0.0022</td> <td>    0.006</td> <td>   -0.348</td> <td> 0.728</td> <td>   -0.014</td> <td>    0.010</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERMINTE</th>                 <td>    0.1068</td> <td>    0.787</td> <td>    0.136</td> <td> 0.892</td> <td>   -1.436</td> <td>    1.650</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AVYRSEXP</th>                 <td>   -0.0411</td> <td>    1.176</td> <td>   -0.035</td> <td> 0.972</td> <td>   -2.346</td> <td>    2.264</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERMINTE:AVYRSEXP</th>        <td>   -0.0031</td> <td>    0.054</td> <td>   -0.057</td> <td> 0.954</td> <td>   -0.108</td> <td>    0.102</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AVSALK</th>                   <td>    0.0131</td> <td>    0.295</td> <td>    0.044</td> <td> 0.965</td> <td>   -0.566</td> <td>    0.592</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERMINTE:AVSALK</th>          <td>   -0.0019</td> <td>    0.013</td> <td>   -0.145</td> <td> 0.885</td> <td>   -0.028</td> <td>    0.024</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>AVYRSEXP:AVSALK</th>          <td>    0.0008</td> <td>    0.020</td> <td>    0.038</td> <td> 0.970</td> <td>   -0.039</td> <td>    0.041</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERMINTE:AVYRSEXP:AVSALK</th> <td> 5.978e-05</td> <td>    0.001</td> <td>    0.068</td> <td> 0.946</td> <td>   -0.002</td> <td>    0.002</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERSPENK</th>                 <td>   -0.3097</td> <td>    4.233</td> <td>   -0.073</td> <td> 0.942</td> <td>   -8.606</td> <td>    7.987</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PTRATIO</th>                  <td>    0.0096</td> <td>    0.919</td> <td>    0.010</td> <td> 0.992</td> <td>   -1.792</td> <td>    1.811</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERSPENK:PTRATIO</th>         <td>    0.0066</td> <td>    0.206</td> <td>    0.032</td> <td> 0.974</td> <td>   -0.397</td> <td>    0.410</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PCTAF</th>                    <td>   -0.0143</td> <td>    0.474</td> <td>   -0.030</td> <td> 0.976</td> <td>   -0.944</td> <td>    0.916</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERSPENK:PCTAF</th>           <td>    0.0105</td> <td>    0.098</td> <td>    0.107</td> <td> 0.915</td> <td>   -0.182</td> <td>    0.203</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PTRATIO:PCTAF</th>            <td>   -0.0001</td> <td>    0.022</td> <td>   -0.005</td> <td> 0.996</td> <td>   -0.044</td> <td>    0.044</td>\n",
       "</tr>\n",
       "<tr>\n",
       "  <th>PERSPENK:PTRATIO:PCTAF</th>   <td>   -0.0002</td> <td>    0.005</td> <td>   -0.051</td> <td> 0.959</td> <td>   -0.010</td> <td>    0.009</td>\n",
       "</tr>\n",
       "</table>"
      ],
      "text/plain": [
       "<class 'statsmodels.iolib.summary.Summary'>\n",
       "\"\"\"\n",
       "                 Generalized Linear Model Regression Results                  \n",
       "==============================================================================\n",
       "Dep. Variable:                SUCCESS   No. Observations:                  303\n",
       "Model:                            GLM   Df Residuals:                      282\n",
       "Model Family:                Binomial   Df Model:                           20\n",
       "Link Function:                  logit   Scale:                          1.0000\n",
       "Method:                          IRLS   Log-Likelihood:                -127.33\n",
       "Date:                Tue, 24 Dec 2019   Deviance:                       8.5477\n",
       "Time:                        14:57:00   Pearson chi2:                     8.48\n",
       "No. Iterations:                     4                                         \n",
       "Covariance Type:            nonrobust                                         \n",
       "============================================================================================\n",
       "                               coef    std err          z      P>|z|      [0.025      0.975]\n",
       "--------------------------------------------------------------------------------------------\n",
       "Intercept                    0.4037     25.036      0.016      0.987     -48.665      49.472\n",
       "double_it(LOWINC)           -0.0102      0.005     -1.982      0.048      -0.020      -0.000\n",
       "PERASIAN                     0.0159      0.017      0.910      0.363      -0.018       0.050\n",
       "PERBLACK                    -0.0198      0.020     -1.004      0.316      -0.058       0.019\n",
       "PERHISP                     -0.0096      0.010     -0.951      0.341      -0.029       0.010\n",
       "PCTCHRT                     -0.0022      0.022     -0.103      0.918      -0.045       0.040\n",
       "PCTYRRND                    -0.0022      0.006     -0.348      0.728      -0.014       0.010\n",
       "PERMINTE                     0.1068      0.787      0.136      0.892      -1.436       1.650\n",
       "AVYRSEXP                    -0.0411      1.176     -0.035      0.972      -2.346       2.264\n",
       "PERMINTE:AVYRSEXP           -0.0031      0.054     -0.057      0.954      -0.108       0.102\n",
       "AVSALK                       0.0131      0.295      0.044      0.965      -0.566       0.592\n",
       "PERMINTE:AVSALK             -0.0019      0.013     -0.145      0.885      -0.028       0.024\n",
       "AVYRSEXP:AVSALK              0.0008      0.020      0.038      0.970      -0.039       0.041\n",
       "PERMINTE:AVYRSEXP:AVSALK  5.978e-05      0.001      0.068      0.946      -0.002       0.002\n",
       "PERSPENK                    -0.3097      4.233     -0.073      0.942      -8.606       7.987\n",
       "PTRATIO                      0.0096      0.919      0.010      0.992      -1.792       1.811\n",
       "PERSPENK:PTRATIO             0.0066      0.206      0.032      0.974      -0.397       0.410\n",
       "PCTAF                       -0.0143      0.474     -0.030      0.976      -0.944       0.916\n",
       "PERSPENK:PCTAF               0.0105      0.098      0.107      0.915      -0.182       0.203\n",
       "PTRATIO:PCTAF               -0.0001      0.022     -0.005      0.996      -0.044       0.044\n",
       "PERSPENK:PTRATIO:PCTAF      -0.0002      0.005     -0.051      0.959      -0.010       0.009\n",
       "============================================================================================\n",
       "\"\"\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def double_it(x):\n",
    "    return 2 * x\n",
    "formula = 'SUCCESS ~ double_it(LOWINC) + PERASIAN + PERBLACK + PERHISP + PCTCHRT + \\\n",
    "           PCTYRRND + PERMINTE*AVYRSEXP*AVSALK + PERSPENK*PTRATIO*PCTAF'\n",
    "mod2 = smf.glm(formula=formula, data=dta, family=sm.families.Binomial()).fit()\n",
    "mod2.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As expected, the coefficient for ``double_it(LOWINC)`` in the second model is half the size of the ``LOWINC`` coefficient from the first model:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.02039598715475636\n",
      "-0.020395987154757204\n"
     ]
    }
   ],
   "source": [
    "print(mod1.params[1])\n",
    "print(mod2.params[1] * 2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
